<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>供应商列表</title>

    <link rel="shortcut icon" href="${ctx}/favicon.ico"> <link href="${ctx}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx}/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body>
        <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">                       
                        <div class="ibox-content">
                                <div class="row">
                                    <div class="col-sm-6">
                                       
                                    </div>
                                    <div class="col-sm-6" style="text-align:right;">
                                        <div style="text-align:right">
                                            <label style="float:right;font-size:18px;font-weight:normal;margin-right:10px;">查找：
                                                <input type="search"placeholder="请输入关键词" name="values">
                                                <span class="btn btn-sm btn-primary" onclick="searchInfo()">搜索</span>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            <div class="table-responsive" style="height:450px;">
                                <table class="table table-striped">
                                    <thead>
                                    <tr>
                                        <th>供应商编号</th>
                                        <th>供应商</th>
                                        <th>联系人</th>
                                        <th>联系电话</th>
                                        <th>公司地址</th>
                                        <th>主营业务</th>
                                        <th>备注</th>
                                        <th style="width:80px;">修改</th>
                                        <th style="width:80px;">删除</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:forEach var="supplier" items="${supplierList}">
                                    	<tr id="${supplier.supplier_id}">
                                    		<td>${supplier.supplier_id}</td>
                                    		<td>${supplier.supplier_}</td>
                                    		<td>${supplier.supplier_name}</td>
                                    		<td>${supplier.telephone}</td>
                                    		<td>${supplier.supplier_address}</td>
                                    		<td>${supplier.main_business}</td>
                                    		<td>${supplier.remark}</td>
                                    		<td>
                                            	<a style="font-size:14px;" class="btn btn-primary btn-rounded" onclick="updateInfo(${supplier.supplier_id})">修改</a>
                                        	</td>
                                        	<td>
                                            	<a style="font-size:14px;" class="btn btn-primary btn-rounded" onclick="deleteInfo(${supplier.supplier_id})">删除</a>
                                        	</td>
                                    	</tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                            <div>
                                    <!-- <span style="float:left;">共25条数据5页</span> -->
                                    <div id="page" style="text-align:right;"></div>
                            </div> 
                        </div>
                    </div>
                </div>
        
        </div>
</body>
<!-- 全局js -->
<script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctx}/dist\layer-v3.1.1\layer\layer.js"></script>
<script src="${ctx}/dist/jquery-bootstrap-pagination/jquery-bootstrap-pagination.js"></script>

<script>
  $("#page").pagination({
		  total_pages:${pageCount},
		  current_page:${pageNum},
		  prev: "上一页",
		  next: "下一页",
		  display_max:4,
		  callback: function(event, page){
 			location="${ctx}/SupplierServlet/listSupplier?pageNum="+page;
		}
		});  
    //查找
    function searchInfo(){
        search=$('[name=values]').val();
        location="${ctx}/SupplierServlet/sarchInfo?search="+search;       
    }
    //更改信息
    function updateInfo(supplier_id){
    	layer.open({
 			type:2,
 			content:['${ctx}/SupplierServlet/preEditSupplier?supplier_id='+supplier_id,'no'],
 			area:['65%','75%']
 		});
       
    }
    //删除信息
    function deleteInfo(supplier_id){
        //layer.msg("删除信息");
        $.get('${ctx}/SupplierServlet/moveSupplier',{'supplier_id':supplier_id},function(data){
        	if(data){
        		layer.msg("删除成功！");
        		document.getElementById(supplier_id).parentNode.removeChild(document.getElementById(supplier_id));
        	}else{
        		layer.msg("删除失败！");
        	}
        });
    }
</script>
</html>